<?php $this->load->view('header/admin'); ?>
<div id="main">
    <div class="container">
        <div class="span-17 colborder" id="content">
            <?php if (isset($messages)) echo $messages; ?>
            <h3>Edit Club</h3>
	        <div class="box span-11">
                <form action="" method="post">
			        <p>
				        <label for="name">Name: </label> 
				        <?php echo form_input('name',set_value('name', $club->name), 'size="40"'); ?>
			        </p>
					<p>
					  <label for="since">Since: </label>
					  <input type="text" id="datepicker" size="10" maxlength="10" name="since" value="<?php echo $club->since; ?>"/>
					</p>
					<p>
						<label for="description">Description: </label> 
						<?php echo form_textarea(array('name' => 'description', 'cols' => '35', 'rows' => '5'),
						    set_value('description', $club->description)); ?>
					</p>
					<p>
						<label for="website">Website: </label> 
						<?php echo form_input('website',set_value('website', $club->website), 'size="40"'); ?>
					</p>
					<p>
						<label for="active">Active: </label> 
						<?php echo form_dropdown('active', array (
						1 => 'Yes',
						0 => 'No'
						), set_value('active', $club->active)); ?></p>
					<p>
						<label for="address_line_1">Address: </label> 
						<?php echo form_input('address_line_1',set_value('address_line_1', $club->address_line_1), 'size="40"'); ?>
						<?php echo form_input('address_line_2',set_value('address_line_2', $club->address_line_2), 'size="40"'); ?>
					</p>
					<p>
						<label for="location">Location: </label> 
			    		<?php echo form_input('location',set_value('location', $club->location)); ?>
					</p>
					<p>
			            <label for="postcode">Postcode: </label> 
			            <?php echo form_input('postcode',set_value('postcode', $club->postcode)); ?>
					</p>
					<p>
			            <label for="country_code">Country: </label> 
			            <?php echo form_input('country_code',set_value('country_code', $club->country_code)); ?>
					</p>
					<p style="text-align: right"><?php echo form_submit('action','Update'); ?></p>
                </form>
            </div>
            <div class="span-5 last">
                    <div class="box">
                        <h3 class="section-title">Authorities</h3>
                        <p>Enter a name to search and then add the person</p>
                        <?php echo form_open('admin/clubs/authorities/search/'.$club->id); ?>
                        <p>
                            <label for="authority_term" id="authority_name">Search</label> 
                            <input type="text" id="authority_autocomplete" name="authority_term" />
                        </p>
                        <p style="text-align: right; margin-right: 10px">
                            <input type="submit" name="action" value="Search" />
                        </p>
                        <?php echo form_close(); ?>
                        
                        <?php if (isset($authority_search_results) && count($authority_search_results) > 0): ?>
                        <?php echo form_open('admin/clubs/authorities/add/'.$club->id); ?>
                        <p>
                            <label for="person" id="authority_name">Results</label>
                            <?php echo form_dropdown('authority_id', $authority_search_results); ?>
                        </p>
                        <p>
                            <label for="person" id="authority_position">Position</label>
                            <?php echo form_input('authority_position'); ?>
                        </p>
                        <p style="text-align: right; margin-right: 10px">
                            <input type="submit" name="action" value="Add" />
                        </p>
                        <?php echo form_close(); ?>
                        
                        <?php endif; ?>
                        <?php if (count($club->Authorities) > 0): ?>
                        <h5>List of authorities</h5>
                        <dl>
                        <?php foreach ($club->Authorities as $e): ?>
                            <dt>
                                <?php echo anchor('profile/person/edit/'.$e->id, $e->name); ?>
                                [<?php echo anchor('admin/clubs/authorities/delete/'.$club->id.'/'.$e->id, 'x')?>]
                            </dt>
                            <dd><?php echo $e->ClubAuthorityModel[0]->position; ?></dd>
                        <?php endforeach; ?>
                        </dl>
                        <?php endif; ?>
                    </div>
                    
                    <div class="box">
                        <h3 class="section-title">Contacts</h3>
                        <p>Enter a name to search and then add the person</p>
                        <?php echo form_open('admin/clubs/contacts/search/'.$club->id); ?>
                        <p>
                            <label for="contact_term" id="contact_name">Search</label> 
                            <input type="text" id="contact_autocomplete" name="contact_term" />
                        </p>
                        <p style="text-align: right; margin-right: 10px">
                            <input type="submit" name="action" value="Search" />
                        </p>
                        <?php echo form_close(); ?>
                        
                        <?php if (isset($contact_search_results) && count($contact_search_results) > 0): ?>
                        <?php echo form_open('admin/clubs/contacts/add/'.$club->id); ?>
                        <p>
                            <label for="person" id="contact_name">Results</label>
                            <?php echo form_dropdown('contact_id', $contact_search_results); ?>
                        </p>
                        <p style="text-align: right; margin-right: 10px">
                            <input type="submit" name="action" value="Add" />
                        </p>
                        <?php echo form_close(); ?>
                        
                        <?php endif; ?>
                        <?php if (count($club->Contacts) > 0): ?>
                        <h5>List of contacts</h5>
                        <ul>
                        <?php foreach ($club->Contacts as $e): ?>
                            <li>
                                <?php echo anchor('profile/person/edit/'.$e->id, $e->name); ?>
                                [<?php echo anchor('admin/clubs/contacts/delete/'.$club->id.'/'.$e->id, 'x')?>]
                            </li>
                        <?php endforeach; ?>
                        </ul>
                        <?php endif; ?>
                    </div>
                    
                    <div class="box">
	                    <h3 class="section-title">Admins</h3>
	                    <p>Enter a name to search and then add the person</p>
                        <?php echo form_open('admin/clubs/admins/search/'.$club->id); ?>
                        <p>
                            <label for="admin_term" id="admin_name">Search</label> 
                            <input type="text" id="admin_autocomplete" name="admin_term" />
                        </p>
                        <p style="text-align: right; margin-right: 10px">
                            <input type="submit" name="action" value="Search" />
                        </p>
                        <?php echo form_close(); ?>
                        
                        <?php if (isset($admin_search_results) && count($admin_search_results) > 0): ?>
                        <?php echo form_open('admin/clubs/admins/add/'.$club->id); ?>
                        <p>
                            <label for="person" id="admin_name">Results</label>
                            <?php echo form_dropdown('admin_id', $admin_search_results); ?>
                        </p>
                        <p style="text-align: right; margin-right: 10px">
                            <input type="submit" name="action" value="Add" />
                        </p>
                        <?php echo form_close(); ?>
                        
                        <?php endif; ?>
                        <?php if (count($club->Admins) > 0): ?>
                        <h5>List of admins</h5>
                        <ul>
                        <?php foreach ($club->Admins as $e): ?>
                            <li>
                                <?php echo anchor('profile/person/edit/'.$e->id, $e->name); ?>
                                [<?php echo anchor('admin/clubs/admins/delete/'.$club->id.'/'.$e->id, 'x')?>]
                            </li>
                        <?php endforeach; ?>
                        </ul>
                        <?php endif; ?>
                    </div>
            </div>
        </div> <!-- end content -->
        <?php $this->load->view('menu/admin')?>
    </div> <!-- end container -->
    <script type="text/javascript">
        $(document).ready(function() {
            $("#datepicker").datepicker({
                dateFormat: 'yy-mm-dd',
                changeMonth: true,
                changeYear: true,
                yearRange: 'c-100:c'
            });
            
           /* $('#authority_autocomplete').simpleAutoComplete('<?php echo site_url('admin/people/ajax_acquery');?>',{
                autoCompleteClassName: 'autocomplete',
                selectedClassName: 'sel',
                attrCallBack: 'rel',
                identifier: 'name'
                }, authorityCallback);

                $('#contact_autocomplete').simpleAutoComplete('<?php echo site_url('admin/people/ajax_acquery');?>',{
                    autoCompleteClassName: 'autocomplete',
                    selectedClassName: 'sel',
                    attrCallBack: 'rel',
                    identifier: 'name'
                    }, contactCallback);
            
        	$('#admin_autocomplete').simpleAutoComplete('<?php echo site_url('admin/people/ajax_acquery');?>',{
                autoCompleteClassName: 'autocomplete',
                selectedClassName: 'sel',
                attrCallBack: 'rel',
                identifier: 'name'
                }, adminCallback);*/
        });

        function authorityCallback(par) {
            var url = '<?php echo site_url('admin/clubs/add_ajax/'.$club->id.'/authority/')?>/' + par[1];

            $('#authority_id').attr('href',url);
        }

        function contactCallback(par) {
            var url = '<?php echo site_url('admin/clubs/add_ajax/'.$club->id.'/contact/')?>/' + par[1];

            $('#contact_id').attr('href',url);
        }
        function adminCallback(par) {
            var url = '<?php echo site_url('admin/clubs/add_ajax/'.$club->id.'/admin/')?>/' + par[1];

            $('#admin_id').attr('href',url);
        }
        </script>
</div> <!-- end main -->
<?php $this->load->view('footer/standard');?>
